package com.sgb.kjwl.viewmodel.packers;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.packers.PackerNationEntity;
import com.swgk.core.base.model.entity.BaseEntity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author : younghow
 * @date : 2021/7/21 12:01
 * description:其他要求的viewModel，在这里进行数据的统一处理和分发
 */
public class  OtherAskViewModel extends AndroidViewModel {

    /**
     * 获取网络请求时需要的livedata，这里有三种状态来针对网络请求的展示进行统一处理，分加载，成功，失败
     */
    public MutableLiveData<Boolean> loadingLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> successLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> errorLiveData = new MutableLiveData<>();
    /**
     * 获取民族的livedata
     */
    public MutableLiveData<List<PackerNationEntity>> mNationLiveDta = new MutableLiveData<>();

    public OtherAskViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /**
     * 薪资管理的数据来源
     * @return 薪资管理的数据
     */
    public List<PickSelectEntity> getSalaryManagement() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("保底工资");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("绩效工资");
        listFs.add(entity1);
        listFs.add(entity2);
        return listFs;
    }

    /**
     * 薪资发放的数据来源
     * @return 薪资发放的数据
     */
    public List<PickSelectEntity> getPayrollPayment() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("按月");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("按季度");
        PickSelectEntity entity3 = new PickSelectEntity();
        entity3.setNo("3");
        entity3.setProjectscale("按年度");
        listFs.add(entity1);
        listFs.add(entity2);
        listFs.add(entity3);
        return listFs;
    }

    /**
     * 年龄要求的数据来源
     * @return 年龄要求的数据
     */
    public List<PickSelectEntity> getAgeRequirements() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("不限");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("15-25岁");
        PickSelectEntity entity3 = new PickSelectEntity();
        entity3.setNo("3");
        entity3.setProjectscale("25-35岁");
        PickSelectEntity entity4 = new PickSelectEntity();
        entity4.setNo("4");
        entity4.setProjectscale("35-45岁");
        PickSelectEntity entity5 = new PickSelectEntity();
        entity5.setNo("5");
        entity5.setProjectscale("45-55岁");
        PickSelectEntity entity6 = new PickSelectEntity();
        entity6.setNo("6");
        entity6.setProjectscale("55岁以上");
        listFs.add(entity1);
        listFs.add(entity2);
        listFs.add(entity3);
        listFs.add(entity4);
        listFs.add(entity5);
        listFs.add(entity6);
        return listFs;
    }

    /**
     * 工龄要求的数据来源
     * @return 工龄要求的数据
     */
    public List<PickSelectEntity> getLengthOfServiceRequirements() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("不限");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("1年以内");
        PickSelectEntity entity3 = new PickSelectEntity();
        entity3.setNo("3");
        entity3.setProjectscale("1-3年");
        PickSelectEntity entity4 = new PickSelectEntity();
        entity4.setNo("4");
        entity4.setProjectscale("3-5年");
        PickSelectEntity entity5 = new PickSelectEntity();
        entity5.setNo("5");
        entity5.setProjectscale("5-10年");
        PickSelectEntity entity6 = new PickSelectEntity();
        entity6.setNo("6");
        entity6.setProjectscale("10年以上");
        listFs.add(entity1);
        listFs.add(entity2);
        listFs.add(entity3);
        listFs.add(entity4);
        listFs.add(entity5);
        listFs.add(entity6);
        return listFs;
    }

    /**
     * 网络获取民族要求的数据来源
     */
    public void getNationRequirements() {
        loadingLiveData.postValue(true);
        APIManager.getInstance().getPackerAPI().getNationList1().enqueue(new Callback<BaseEntity<List<PackerNationEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PackerNationEntity>>> call, Response<BaseEntity<List<PackerNationEntity>>> response) {
                successLiveData.postValue(true);
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    PackerNationEntity pickSelectEntity = new PackerNationEntity();
                    pickSelectEntity.setNo("0");
                    pickSelectEntity.setProjectscale("不限");
                    response.body().getData().add(0,pickSelectEntity);
                    mNationLiveDta.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PackerNationEntity>>> call, Throwable t) {
                errorLiveData.postValue(true);
            }
        });
    }

    /**
     * 健康证明需求与否的数据来源
     * @return 健康证明需求与否的数据
     */
    public List<PickSelectEntity> getMedicalCertificate() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("需要");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("不需要");
        listFs.add(entity1);
        listFs.add(entity2);
        return listFs;
    }

    /**
     * 性别要求的数据来源
     * @return 性别要求的数据
     */
    public List<PickSelectEntity> getSexRequirements() {
        List<PickSelectEntity> listFs = new ArrayList<>();
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("不限");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("2");
        entity2.setProjectscale("男");
        PickSelectEntity entity3 = new PickSelectEntity();
        entity3.setNo("3");
        entity3.setProjectscale("女");
        listFs.add(entity1);
        listFs.add(entity3);
        listFs.add(entity2);
        return listFs;
    }
}
